//封装分类数据业务相关代码
import {getCategoryAPI} from "@/apis/category.js";
import {onMounted,ref} from 'vue'
import {onBeforeRouteUpdate, useRoute} from "vue-router";
export function useCategory(){
  //获取数据
  const categoryDate = ref({})
  const route = useRoute()
  const getCategory = async (id = route.params.id) =>{
    const res = await getCategoryAPI(id)
    categoryDate.value = res.result
  }

  onMounted(()=>{getCategory()})

  onBeforeRouteUpdate(async (to) =>{
    await getCategory(to.params.id);
  });
  return{
    categoryDate
  }

}
